function [n, t] = srf_TrianglesToNeighbors(hfile, triref)
% SRF::TrianglesToNeighbors  - get full 1. order neighbors lists
%
% FORMAT:       [nei, tri] = srf.TrianglesToNeighbors([triref]);
%
% Input fields:
%
%       triref      optional boolean flag, create triangle ref list as well
%
% Output fields:
%
%       nei         Vx2 cell array, neighbors lists (for Neighbors property)
%       tri         Vx1 cell array, triangle back-reference lists

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% check arguments
if nargin < 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'srf')
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end

% get contents
bc = bvqxfile_getcont(hfile.L);
nc = size(bc.VertexCoordinate, 1);

% which call
if nargin > 1 && ...
    islogical(triref) && ...
    numel(triref) == 1 && ...
    triref
    [n, bd, t] = mesh_trianglestoneighbors(nc, bc.TriangleVertex);
else
    n = mesh_trianglestoneighbors(nc, bc.TriangleVertex);
end
